#pragma once
#include "Plane.h"
#include <glm/mat4x4.hpp>

class Ray;
class Rect;
class BoundingBox;
class BoundingSphere;

enum FrustumPlane
{
	Near = 0,
	Left,
	Right,
	Up,
	Down,
	Far,
};

class Frustum
{
public:
	Frustum();
	Frustum(const glm::mat4& transform);
	Frustum(const glm::mat4& projection, const glm::mat4& view);
	~Frustum();

	void Transform(const glm::mat4& transform);
	void Define(const glm::mat4& projection, const glm::mat4& view);
	void Define(const glm::mat4& transform);
	void DefineOrtho(float scale, float aspectRatio, float near, float far, const glm::mat4& viewMatrix);
	void Define(float fov, float aspectRatio, float near, float far, const glm::mat4& viewMatrix);

	bool IsInside(const glm::vec3& point) const;
	bool IsInside(const BoundingSphere& sphere) const;
	bool IsInside(const BoundingBox& box) const;
	bool IsInside(const Rect& rect) const;
	bool IsInside(const Plane& plane) const;
	bool IsInside(const Ray& ray) const;

	const Plane& GetPlane(FrustumPlane plane) const;
	const Plane& GetPlane(int index) const { return mPlanes[index]; }
	glm::vec3* GetVerticies();

private:

	void CalculateVertices(const glm::mat4& transform);

	Plane mPlanes[6];
	glm::vec3 mVerticies[8];
};
